import { createRouter, createWebHistory } from "vue-router";
import API from 'api'

// 路由信息
const menu = [
  {
    path: "/index",
    name: "Index",
    component: () => import("@/views/index.vue"),
  },
  {
    path: "/account",
    name: "Account",
    component: () => import("@/views/Customer/index.vue"),
    children: [
      {
        path: "/accountlist",
        name: "AccountList",
        component: () => import("@/views/Customer/List.vue"),
      },
      // {
      //   path: "/contact",
      //   name: "ContactList",
      //   component: () => import("@/views/Customer/Contact.vue"),
      // },
      // {
      //   path: "/customerlogs",
      //   name: "CustomerLogs",
      //   component: () => import("@/views/Customer/Logs.vue"),
      // },

    ],
  },
  {
    path: "/device",
    name: "Device",
    component: () => import("@/views/Equipment/index.vue"),
    children: [
      {
        path: "/deviceList",
        name: "DeviceList",
        component: () => import("@/views/Equipment/List.vue"),
      },
      {
        path: "/tasks",
        name: "Tasks",
        component: () => import("@/views/Equipment/Tasks.vue"),
      },
      {
        path: "/importRecords",
        name: "ImportRecords",
        component: () => import("@/views/Equipment/ImportRecords.vue"),
      },
      // {
      //   path: "/sensorTypes",
      //   name: "SensorTypes",
      //   component: () => import("@/views/Equipment/SensorTypes.vue"),
      // },
      // {
      //   path: "/alarmrecords",
      //   name: "AlarmRecords",
      //   component: () => import("@/views/Equipment/AlarmRecords.vue"),
      // },
      // {
      //   path: "/keepwatchreports",
      //   name: "KeepWatchReports",
      //   component: () => import("@/views/Equipment/KeepWatchReports.vue"),
      // },
      // {
      //   path: "/noticerecords",
      //   name: "NoticeRecords",
      //   component: () => import("@/views/Equipment/NoticeRecords.vue"),
      // },
    ],
  },
  {
    path: "/role",
    name: "Role",
    component: () => import("@/views/Role/index.vue"),
  },
  {
    path: "/config",
    name: "Config",
    component: () => import("@/views/Config/index.vue"),
  },
];
const routes = [
  {
    path: "/",
    name: "Dashboard",
    component: () => import("@/views/Layout/Dashboard.vue"),
  },
  {
    path: "/produce",
    name: "Produce",
    component: () => import("@/views/produce.vue"),
  },
  {
    path: "/produceLogin",
    name: "ProduceLogin",
    component: () => import("@/views/produceLogin.vue"),
  },
  {
    path: "/privacy-policy",
    name: "Privacy",
    component: () => import("@/views/Layout/Privacy.vue"),
  },
  {
    path: "/login",
    name: "Login",
    component: () => import("@/views/login.vue"),
  },
  {
    path: "/user_info",
    name: "UserInfo",
    component: () => import("@/views/Layout/info.vue"),
  },
  {
    path: "/account",
    name: "Account",
    component: () => import("@/views/Customer/index.vue"),
    children: [
      {
        path: "/accountlist",
        name: "AccountList",
        component: () => import("@/views/Customer/List.vue"),
      },
      // {
      //   path: "/contact",
      //   name: "ContactList",
      //   component: () => import("@/views/Customer/Contact.vue"),
      // },
      // {
      //   path: "/customerlogs",
      //   name: "CustomerLogs",
      //   component: () => import("@/views/Customer/Logs.vue"),
      // },
    ],
  },
  {
    path: "/device",
    name: "Device",
    component: () => import("@/views/Equipment/index.vue"),
    children: [
      {
        path: "/deviceList",
        name: "DeviceList",
        component: () => import("@/views/Equipment/List.vue"),
      },
      {
        path: "/tasks",
        name: "Tasks",
        component: () => import("@/views/Equipment/Tasks.vue"),
      },
      {
        path: "/importRecords",
        name: "ImportRecords",
        component: () => import("@/views/Equipment/ImportRecords.vue"),
      },
      // {
      //   path: "/sensorTypes",
      //   name: "SensorTypes",
      //   component: () => import("@/views/Equipment/SensorTypes.vue"),
      // },
      // {
      //   path: "/alarmrecords",
      //   name: "AlarmRecords",
      //   component: () => import("@/views/Equipment/AlarmRecords.vue"),
      // },
      // {
      //   path: "/keepwatchreports",
      //   name: "KeepWatchReports",
      //   component: () => import("@/views/Equipment/KeepWatchReports.vue"),
      // },
      // {
      //   path: "/noticerecords",
      //   name: "NoticeRecords",
      //   component: () => import("@/views/Equipment/NoticeRecords.vue"),
      // },
    ],
  },
  {
    path: "/role",
    name: "Role",
    component: () => import("@/views/Role/index.vue"),
  },
  {
    path: "/config",
    name: "Config",
    component: () => import("@/views/Config/index.vue"),
  },
  {
    path: "/index",
    name: "Index",
    component: () => import("@/views/index.vue"),
  },
  {
    path: "/alexaLogin",
    name: "AlexaLogin",
    component: () => import("@/views/AlexaLogin.vue"),
  },
];
// 导出路由
const router = createRouter({
  history: createWebHistory(),
  routes,
});
export var getRoutes = (ids = []) => {
  if (ids.length > 0) {
    let m = []
    let device = {}
    let customerChildren = []
    let deviceChildren = []
    m.push({
      path: "/index",
      name: "Index",
      component: () => import("@/views/index.vue"),
    })
    if (ids.includes(8) || ids.includes(9) || ids.includes(10) || ids.includes(11) || ids.includes(12)) {
      customerChildren.push({
        path: "/accountlist",
        name: "AccountList",
        component: () => import("@/views/Customer/List.vue"),
      })
      // customerChildren.push({
      //   path: "/contact",
      //   name: "ContactList",
      //   component: () => import("@/views/Customer/Contact.vue"),
      // })
      m.push({
        path: "/account",
        name: "Account",
        component: () => import("@/views/Customer/index.vue"),
        children: customerChildren
      })
    }
    if (ids.includes(1) || ids.includes(4) || ids.includes(5) || ids.includes(6) || ids.includes(7)) {
      deviceChildren.push({
        path: "/deviceList",
        name: "DeviceList",
        component: () => import("@/views/Equipment/List.vue"),
      })
      if (ids.includes(7)) {
        deviceChildren.push({
          path: "/tasks",
          name: "Tasks",
          component: () => import("@/views/Equipment/Tasks.vue"),
        })
      }
      if (ids.includes(19)) {
        deviceChildren.push({
          path: "/importRecords",
          name: "ImportRecords",
          component: () => import("@/views/Equipment/ImportRecords.vue"),
        })
      }
      if (ids.includes(13)) {
        // deviceChildren.push({
        //   path: "/sensorTypes",
        //   name: "SensorTypes",
        //   component: () => import("@/views/Equipment/SensorTypes.vue"),
        // })
      }
      m.push({
        path: "/device",
        name: "Device",
        component: () => import("@/views/Equipment/index.vue"),
        children: deviceChildren
      })
    }
    if (ids.includes(16)) {
      m.push({
        path: "/role",
        name: "Role",
        component: () => import("@/views/Role/index.vue"),
      })
    }
    if (ids.includes(15)) {
      m.push({
        path: "/config",
        name: "Config",
        component: () => import("@/views/Config/index.vue"),
      })
    }
    return m
  }
  return menu
};

export default router;
